package com.huawei.appgallery.search.ui.card;

import android.content.Context;
import android.view.View;
import android.view.ViewGroup;
import android.widget.LinearLayout;
import android.widget.TextView;
import androidx.annotation.NonNull;
import com.huawei.appgallery.foundation.ui.framework.cardframe.bean.BaseCardBean;
import com.huawei.appgallery.foundation.ui.framework.cardkit.bean.CardBean;
import java.util.ArrayList;
import java.util.List;
import o.cgz;
import o.chy;
import o.cuv.b;
import o.cvi;
import o.dof;
import o.evx;

public class BaseCompositeCard extends cgz {
    private LinearLayout ˊ;
    private View ˋ;
    private View ˎ;
    List<BaseCompositeItemCard> ˏ = new ArrayList();
    protected chy ॱ;

    public BaseCompositeCard(Context context) {
        super(context);
    }

    public List<BaseCompositeItemCard> ˊ() {
        return this.ˏ;
    }

    public void ˋ(BaseCompositeItemCard baseCompositeItemCard) {
        this.ˏ.add(baseCompositeItemCard);
    }

    public BaseCompositeItemCard ˋ() {
        return new BaseCompositeItemCard(this.ʼॱ);
    }

    public View ˎ() {
        return new View(this.ʼॱ);
    }

    public ViewGroup ॱॱ() {
        return this.ˊ;
    }

    public View ʽ() {
        return this.ˎ;
    }

    public View ʼ() {
        return this.ˋ;
    }

    public cgz ˏ(View view) {
        ॱ((TextView) view.findViewById(b.ʾ));
        this.ˎ = view.findViewById(b.ᐝॱ);
        this.ˊ = (LinearLayout) view.findViewById(b.ˎˎ);
        this.ˋ = view.findViewById(b.ॱˎ);
        ʽ(view);
        return this;
    }

    public void ˏ(CardBean cardBean) {
        super.ˏ(cardBean);
        if (cardBean instanceof cvi) {
            cvi o_cvi = (cvi) cardBean;
            List ˊ = o_cvi.ˊ();
            int size = ˊ == null ? 0 : ˊ.size();
            ˊ(o_cvi, size);
            int min = Math.min(size, ᐝ());
            int size2 = this.ˏ.size();
            ViewGroup ॱॱ = ॱॱ();
            if (ॱॱ != null) {
                int i;
                View ˉ;
                if (size2 > min) {
                    for (i = size2 - 1; i >= min; i--) {
                        BaseCompositeItemCard baseCompositeItemCard = (BaseCompositeItemCard) this.ˏ.get(i);
                        if (baseCompositeItemCard != null) {
                            ˉ = baseCompositeItemCard.ˉ();
                            if (ˉ != null) {
                                ॱॱ.removeView(ˉ);
                            }
                            this.ˏ.remove(baseCompositeItemCard);
                        }
                    }
                }
                for (i = 0; i < min; i++) {
                    BaseCardBean baseCardBean = (BaseCardBean) ˊ.get(i);
                    if (baseCardBean != null) {
                        baseCardBean.ˋˋ(o_cvi.ॱˉ());
                        baseCardBean.ʻ(o_cvi.ॱㆍ());
                        BaseCompositeItemCard baseCompositeItemCard2;
                        if (i < size2) {
                            baseCompositeItemCard2 = (BaseCompositeItemCard) this.ˏ.get(i);
                            baseCompositeItemCard2.ˏ(min);
                            baseCompositeItemCard2.ᐝ(i);
                            baseCompositeItemCard2.ˏ((CardBean) baseCardBean);
                        } else {
                            baseCompositeItemCard2 = ˋ();
                            baseCompositeItemCard2.ˏ(min);
                            baseCompositeItemCard2.ᐝ(i);
                            ˉ = ˎ();
                            ॱॱ.addView(ˉ);
                            baseCompositeItemCard2.ˏ(ˉ);
                            baseCompositeItemCard2.ˏ((CardBean) baseCardBean);
                            baseCompositeItemCard2.ॱ(this.ॱ);
                            ˋ(baseCompositeItemCard2);
                        }
                    }
                }
            }
            ॱ(o_cvi.ॱㆍ());
        }
    }

    private void ˊ(@NonNull CardBean cardBean, int i) {
        if (this.ʿ != null) {
            this.ʿ.setText(cardBean.v_());
        }
        String ॱॱ = cardBean.ॱॱ();
        View ʽ = ʽ();
        if (ʽ == null) {
            return;
        }
        if (ˎ(ॱॱ, i)) {
            ʽ.setVisibility(0);
        } else {
            ʽ.setVisibility(8);
        }
    }

    protected void ॱ(boolean z) {
        View ʼ = ʼ();
        if (ʼ == null) {
            return;
        }
        if (z) {
            ʼ.setVisibility(8);
        } else {
            ʼ.setVisibility(0);
        }
    }

    public void ॱ(final chy o_chy) {
        this.ॱ = o_chy;
        View ʽ = ʽ();
        if (ʽ != null) {
            ʽ.setOnClickListener(new evx(this) {
                final /* synthetic */ BaseCompositeCard ˏ;

                public void ˋ(View view) {
                    if (o_chy != null) {
                        o_chy.ˏ(9, this.ˏ);
                    }
                }
            });
        }
    }

    public int ᐝ() {
        return 3;
    }

    protected boolean ˎ(String str, int i) {
        return !dof.ॱ(str) && i >= ᐝ();
    }
}
